package cate.game.play.skill.passive.fairy;

import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.effect.SkillEffect;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.Comparator;
import java.util.List;

/**
 * 效果2：星罗棋布’额外对1个相邻目标造成伤害，相邻目标优先前排
 */
public class 星空蛋糕灵器PH extends PassiveHandler {

	private String 技能标签;

	//技能标签=星罗棋布
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		技能标签 = args.get("技能标签");
	}

	@Override
	public void afterSelectTargets(SkillActionCtx action, SkillEffect effect) {
		if (!action.getSkill().cfg.containTag(技能标签)) {
			return;
		}
		List<Fighter> nearTargets = TargetSelector.findNear(action.getTeamVs().getEnemyTeam(skill.owner.getTeam()).getFightersAlive(), action.getTargets());
		nearTargets.stream().min(Comparator.comparing(Fighter::getPos)).ifPresent(addTarget -> action.getTargets().add(addTarget));
	}
}
